/**
 * 
 */
package it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.actions;

import java.util.LinkedList;

import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.GUIDStorage;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.GameManager;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.MatchManager;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.component.player.BattlePlayer;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.component.player.SimplePlayer;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.EventManager;
import it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.events.TurnEvent;

/**
 * @author Massimo Canonaco
 *
 */
public class EndTurnAction implements GenericLogicAction {

	/** */
	private static final String emptyString = new String();
	
	/** */
	private TurnEvent turnEvent;
	
	/** */
	private MatchManager matchManager;
	
	/** */
	private BattlePlayer performer;
	
	/** */ 
	static public final float GUID = GUIDStorage.END_TURN_ACTION;
	/** */
	public EndTurnAction(final MatchManager matchManager, final BattlePlayer performer)
	{
		this.matchManager = matchManager;
		this.performer = performer;
		turnEvent = new TurnEvent();
	}
	
	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.actions.Action#getActionIdentifier()
	 */
	@Override
	public float getActionIdentifier() {
		return GUID;
	}

	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.actions.Action#execute(java.util.LinkedList)
	 */
	@Override
	public boolean execute(LinkedList<GenericActionInfo> infos) 
	{
		if(matchManager.getCurrentPlayer().equals(performer))
		{
//			EventManager.getInstance().triggerEvent(turnEvent);
			System.out.println("END TURN ACTION");
			matchManager.nextTurn();
			return true;
		}
		
//		turnEvent.setNewPlayer(performer.getNickname());
//		turnEvent.setOldPlayer(matchManager.getCurrentPlayer().getNickname());
//		turnEvent.setSuccess(false);
		
		return false;
	}

	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.actions.Action#reset()
	 */
	@Override
	public void reset() 
	{
		turnEvent.setNewPlayer(emptyString);
		turnEvent.setOldPlayer(emptyString);
	}

	/* (non-Javadoc)
	 * @see it.unical.canonaco.rende.igpe.game.cbv.logiclayer.engine.actions.Action#isFinished()
	 */
	@Override
	public boolean isFinished() 
	{
		return true;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return "ENDTURN";
	}

}
